<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="okhttp3.*" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.concurrent.TimeUnit" %>
<%--流程退回调用QMS接口--%>
<%
    String url = "http://10.210.64.77:8085/ECSAP2PMS";
    out.println(">>>>>url=" + url+"<br/>");
    JSONObject paramJson = new JSONObject();
    paramJson.put("pmsno", "12324");
    paramJson.put("requestid", "2323");
    paramJson.put("status", "0");
    paramJson.put("batchno", "");
    paramJson.put("type", "EC");
    out.println(">>>>>>paramJson=" + paramJson+"<br/>");
    JSONObject resultJson = sendOKHttpRequest(url,paramJson.toJSONString());
    out.println(">>>>>测试接口>>>>>resultJson=" + resultJson+ "<br/>");
    JSONObject retDataJson = JSONObject.parseObject(resultJson.getString("data"));
    JSONObject outputJson = JSONObject.parseObject(retDataJson.getString("OUTPUT"));
    out.println(">>>>>测试接口>>>>>outputJson=" + outputJson.getString("MSG_TYPE")+ "<br/>");

%>

<%!
    public static JSONObject sendOKHttpRequest(String curl,String params) {
        JSONObject resultJson = new JSONObject();
        String code = "fail";
        String message = "";
        String data = "";
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .connectTimeout(60, TimeUnit.SECONDS)
                    .readTimeout(60, TimeUnit.SECONDS)
                    .writeTimeout(60, TimeUnit.SECONDS)
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, params);
            Request request = new Request.Builder()
                    .url(curl)
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
            String result = Util.null2String(response.body().string());
            if (!"".equals(result)) {
                data = result;
                code = "success";
            } else {
                message = "response result is null";
                code = response.code()+"";
            }
        } catch (Exception e) {
            message = "response timeout";
            e.printStackTrace();
        }
        resultJson.put("code", code);
        resultJson.put("data", data);
        resultJson.put("message", message);
        return resultJson;
    }
%>




